Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

children not rendering anything after upgrading to RN 0.63.0 #429

Closed
bneigher opened this issue Apr 27, 2020 · 19 comments
Closed

children not rendering anything after upgrading to RN 0.63.0 #429

bneigher opened this issue Apr 27, 2020 · 19 comments

Comments

@bneigher
Copy link

After upgrading, it seems that this component may have broken. Does anyone else see this happening?

@nvdnvd00
Copy link

the same issue with me

@tamirrab
Copy link

tamirrab commented May 5, 2020

Same here

@harry503
Copy link

harry503 commented May 7, 2020

It's happening with me too. Does anyone has any solution?

@tankers746
Copy link

tankers746 commented May 8, 2020

This change to ScrollView facebook/react-native@d2f314a

Trips up the listenToKeyboardEvents function in KeyboardAwareHOC.js

A workaround is to create your own KeyboardAwareScrollView by wrapping ScrollView in the listenToKeyboardEvents function.

import { listenToKeyboardEvents } from 'react-native-keyboard-aware-scroll-view';
import { ScrollView } from 'react-native';

const KeyboardAwareScrollView = listenToKeyboardEvents((props) => <ScrollView {...props} />);

@kesha-antonov
Copy link

I created my own simple component as a replacement:

import React from 'react'
import {
  ScrollView,
  KeyboardAvoidingView,
} from 'react-native'
import PropTypes from 'prop-types'

function KeyboardAwareScrollView (props) {
  const {
    behavior,
    children,
    ...rest
  } = props

  return (
    <KeyboardAvoidingView behavior={behavior}>
      <ScrollView
        keyboardShouldPersistTaps='handled'
        {...rest}
      >
        {children}
      </ScrollView>
    </KeyboardAvoidingView>
  )
}

KeyboardAwareScrollView.propTypes = {
  behavior: PropTypes.string.isRequired,
  children: PropTypes.any.isRequired,
}

KeyboardAwareScrollView.defaultProps = {
  behavior: 'position',
}

export default KeyboardAwareScrollView

@ricmatsui
Copy link

Using react-native@0.63.0-rc.1, it seems like type of ScrollView is object which is conflicting with the listenToKeyboardEvents(options)(Comp) version of listenToKeyboardEvents. It seems like it's returning the function (Comp) => KeyboardAwareHOC(Comp, configOrComp) even when called as listenToKeyboardEvents(ScrollView), which triggers the React error:

Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.

Using a custom build with the options version of the function removed fixes the issue for me:

diff --git a/lib/KeyboardAwareHOC.js b/lib/KeyboardAwareHOC.js
index c6e1469..496068b 100644
--- a/lib/KeyboardAwareHOC.js
+++ b/lib/KeyboardAwareHOC.js
@@ -541,11 +541,7 @@ function KeyboardAwareHOC(
 // listenToKeyboardEvents(ScrollView);
 // listenToKeyboardEvents(options)(Comp);
 const listenToKeyboardEvents = (configOrComp: any) => {
-  if (typeof configOrComp === 'object') {
-    return (Comp: Function) => KeyboardAwareHOC(Comp, configOrComp)
-  } else {
-    return KeyboardAwareHOC(configOrComp)
-  }
+  return KeyboardAwareHOC(configOrComp)
 }
 
 export default listenToKeyboardEvents

rohitshampur-dev added a commit to rohitshampur-dev/react-native-keyboard-aware-scroll-view that referenced this issue Jun 24, 2020
->Fix children not rendering anything after upgrading to RN 0.63.0
->Fix from APSL#429 (comment)
@Esxiel
Copy link

Esxiel commented Jul 9, 2020

I sent a different pull request for people who still want the HOC to be usable with configs, but I'm not sure if the maintainer will look at them anytime soon. Also, this naive fix is assuming that only ScrollViews are recognized as objects.

- const listenToKeyboardEvents = (configOrComp: any) => {
-   if (typeof configOrComp === 'object') {
+ const listenToKeyboardEvents = (configOrComp: React.ReactElement | KeyboardAwareHOCProps) => {
+   if(configOrComp?.displayName === "ScrollView") {
+     return KeyboardAwareHOC(configOrComp)
+   }
+   else if (typeof configOrComp === 'object') {

@suupham2506
Copy link

Simply, I use KeyboardAvoidingView and ScrollView. Working perfectly.

@codler
Copy link
Contributor

codler commented Jul 11, 2020

React-native 0.63.0 have been released and it has still issue

@codler
Copy link
Contributor

codler commented Jul 12, 2020

I have forked the repo to fix this issue.

npm i @codler/react-native-keyboard-aware-scroll-view

@rborn rborn closed this as completed in 1fb7ed4 Jul 14, 2020
rborn added a commit that referenced this issue Jul 14, 2020
Fix #429 for broken react-native 0.63.0. Detect Forwarding Refs
@bneigher
Copy link
Author

@rborn can you tag a new version? npm is installing an older version still

@rborn
Copy link
Collaborator

rborn commented Jul 15, 2020

@bneigher don't have yet npm rights :) working on it, will let you know

@bneigher
Copy link
Author

@rborn you can still make the tag and version in github, and npm should be able to recognize the new code.

@bneigher
Copy link
Author

but for now I can hardcode github / master in my package.json

@rborn
Copy link
Collaborator

rborn commented Jul 15, 2020

@bneigher tag created, I talked to the owner of the package and he'll push to npm when he has a little time :)

@CyrusZei
Copy link

well, since this repo is dying, react-native has already solved this problem.

KeyboardAvoidingView and it is really easy to use.

import React from 'react';
import { 
    ScrollView,
    KeyboardAvoidingView,
    TextInput, StyleSheet,
    Text,
    Platform,
    Button,
    Keyboard
} from 'react-native';

const KeyboardAvoidingComponent = () => {
  return (
    <KeyboardAvoidingView
      behavior={Platform.OS == "ios" ? "padding" : "height"}
      style={styles.container}
    >
      <ScrollView keyboardShouldPersistTaps="handled">
        <View style={styles.inner}>
          <Text style={styles.header}>Header</Text>
          <TextInput placeholder="Username" style={styles.textInput} />
          <View style={styles.btnContainer}>
            <Button title="Submit" onPress={() => null} />
          </View>
        </View>
      </TouchableWithoutFeedback>
    </KeyboardAvoidingView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  inner: {
    padding: 24,
    flex: 1,
    justifyContent: "space-around"
  },
  header: {
    fontSize: 36,
    marginBottom: 48
  },
  textInput: {
    height: 40,
    borderColor: "#000000",
    borderBottomWidth: 1,
    marginBottom: 36
  },
  btnContainer: {
    backgroundColor: "white",
    marginTop: 12
  }
});

export default KeyboardAvoidingComponent;



that is all you need to add and it will fix it.

@export-mike
Copy link

export-mike commented Nov 16, 2020

@codler thanks for publishing the fork I tried the options from @CyrusZei and @kesha-antonov

And found they both resulted in strange whitespace being added to android on my forms and on ios I found pressing next on the keyboard didn't always scroll down to the next input. especially on the last input in a form

Using the fork was the best option for me, as it resulted in making no changes to the existing forms in my app

@BenoitFroment
Copy link

@codler Thanks too

@wilmerjpg
Copy link

Thanks @codler !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests